<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="reservation" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{reservationHome.managed ? 'Edit' : 'Add'} Reservation</f:facet>





            <s:decorate id="dateReservationField" template="layout/edit.xhtml">
                <ui:define name="label">Date reservation</ui:define>
                <rich:calendar id="dateReservation"
                          value="#{reservationHome.instance.dateReservation}" datePattern="MM/dd/yyyy hh:mm a"/>
            </s:decorate>


            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{reservationHome.persist}"
                       disabled="#{!reservationHome.wired}"
                       rendered="#{!reservationHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{reservationHome.update}"
                       rendered="#{reservationHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{reservationHome.remove}"
                      immediate="true"
                       rendered="#{reservationHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/Reservation.xhtml"
                rendered="#{reservationHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty reservationFrom ? 'ReservationList' : reservationFrom}.xhtml"
                rendered="#{!reservationHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Client *" labelClass="required">
    <div class="association" id="clientParent">

        <h:outputText value="There is no client associated with this reservation."
                   rendered="#{reservationHome.instance.client == null}"/>

        <rich:dataTable var="_client"
                   value="#{reservationHome.instance.client}"
                rendered="#{reservationHome.instance.client != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="clientTable">
            <h:column>
                <f:facet name="header">Idclient</f:facet>
                <h:outputText value="#{_client.idclient}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Login</f:facet>
                <h:outputText value="#{_client.login}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{reservationHome.instance.client != null ? 'changeParentclient' : 'selectParentclient'}" value="#{reservationHome.instance.client != null ? 'Change' : 'Select'} client"
                       view="/ClientList.xhtml">
                <f:param name="from" value="ReservationEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>

    <rich:tab label="Voyage *" labelClass="required">
    <div class="association" id="voyageParent">

        <h:outputText value="There is no voyage associated with this reservation."
                   rendered="#{reservationHome.instance.voyage == null}"/>

        <rich:dataTable var="_voyage"
                   value="#{reservationHome.instance.voyage}"
                rendered="#{reservationHome.instance.voyage != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="voyageTable">
            <h:column>
                <f:facet name="header">Id voyage</f:facet>
                <h:outputText value="#{_voyage.idVoyage}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Train idtrain</f:facet>
                <h:outputText value="#{_voyage.train.idtrain}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Date depart</f:facet>
                <h:outputText value="#{_voyage.dateDepart}">
                    <s:convertDateTime type="both" dateStyle="short"/>
                </h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Date arrivee</f:facet>
                <h:outputText value="#{_voyage.dateArrivee}">
                    <s:convertDateTime type="both" dateStyle="short"/>
                </h:outputText>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{reservationHome.instance.voyage != null ? 'changeParentvoyage' : 'selectParentvoyage'}" value="#{reservationHome.instance.voyage != null ? 'Change' : 'Select'} voyage"
                       view="/VoyageList.xhtml">
                <f:param name="from" value="ReservationEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>

    <rich:tab label="Tickets">
        <h:form styleClass="association" id="ticketsChildren">

            <h:outputText value="There are no tickets associated with this reservation."
                       rendered="#{empty reservationHome.tickets}"/>

            <rich:dataTable value="#{reservationHome.tickets}"
                           var="_ticket"
                      rendered="#{not empty reservationHome.tickets}"
                    rowClasses="rvgRowOne,rvgRowTwo"
                            id="ticketsTable">
                <rich:column sortBy="#{_ticket.idticket}">
                    <f:facet name="header">Idticket</f:facet>
                    <h:outputText value="#{_ticket.idticket}"/>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{reservationHome.managed}" id="tickets">
        <div class="actionButtons">
            <s:button id="addticket"
                   value="Add ticket"
                    view="/TicketEdit.xhtml"
             propagation="none">
                 <f:param name="reservationIdreservation"
                         value="#{reservationHome.instance.idreservation}"/>
                 <f:param name="ticketFrom" value="Reservation"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
